//
//  search_worksCell.m
//  SoundPill
//
//  Created by 宋鹏鹏 on 15/4/8.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "search_worksCell.h"
#import "plaza_viewModel.h"
#import "AFNetworking.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"
#import "UIViewExt.h"
#define kleftGap  17
#define kupGap   12
#define kDeviceWidth [UIScreen mainScreen].bounds.size.width
#define kImageViewWidth 50
#define kImageViewHeight 50
#define kLabelWidth [UIScreen mainScreen].bounds.size.width - 100
#define kLabelHeight 22

@interface search_worksCell ()
@property (strong, nonatomic) UIImageView *playImage;
@property (strong, nonatomic) UILabel *playCount;
@property (strong, nonatomic) UIImageView *loveImage;
@property (strong, nonatomic) UILabel *loveCount;
@end

@implementation search_worksCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self initSubViews];
        
        //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.backgroundColor=[UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

- (void)initSubViews
{
    // 作品图预览
    self._worksImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self.contentView addSubview:__worksImage];
    
    // 作品标题
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    
    _titleLabel.backgroundColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:_titleLabel];

    // 名字
    
    
    // 发布时间
    _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    _timeLabel.backgroundColor = [UIColor whiteColor];
    _timeLabel.font = [UIFont boldSystemFontOfSize:13];
    [self.contentView addSubview:_timeLabel];
    
    _personName = [[UILabel alloc] initWithFrame:CGRectZero];
    _personName.backgroundColor = [UIColor whiteColor];
    _personName.font = [UIFont boldSystemFontOfSize:13];
    [self.contentView addSubview:_personName];
//    CGRectMake(-5, _workName.frame.origin.y + _workName.frame.size.height -3, (self.frame.size.height - self.frame.size.width) * 0.28, (self.frame.size.height - self.frame.size.width) * 0.28)
    self.playImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    //    _playImage.backgroundColor = [UIColor redColor];
    _playImage.image = [UIImage imageNamed:@"play_gray_button"];
    [self addSubview:_playImage];
//    
    self.playCount = [[UILabel alloc] initWithFrame:CGRectZero];
    self.playCount.font = [UIFont systemFontOfSize:12];
    _playCount.textAlignment = NSTextAlignmentLeft;
    _playCount.textColor = [UIColor colorWithRed:0.600f green:0.600f blue:0.600f alpha:1.00f];
    [self addSubview:_playCount];
//    CGRectMake(_playCount.frame.origin.x + _playCount.frame.size.width - 5, _playImage.frame.origin.y, _playImage.frame.size.width, _playImage.frame.size.height)
    self.loveImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    _loveImage.image = [UIImage imageNamed:@"love_gray_button"];
    [self addSubview:_loveImage];
//    CGRectMake(_loveImage.frame.origin.x + _loveImage.frame.size.width, _loveImage.frame.origin.y, _playCount.frame.size.width+1, _playCount.frame.size.height)
    self.loveCount = [[UILabel alloc] initWithFrame:CGRectZero];
    _loveCount.textColor = [UIColor colorWithRed:0.600f green:0.600f blue:0.600f alpha:1.00f];
    _loveCount.textAlignment = NSTextAlignmentLeft;
    _loveCount.font = [UIFont systemFontOfSize:12];
    
    [self addSubview:_loveCount];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //首图预览
    __worksImage.frame = CGRectMake(kleftGap, kupGap, self.height - 2 * kupGap, self.height - 2 * kupGap);
    __worksImage.backgroundColor=[UIColor whiteColor];
    //_worksImage.image=[UIImage imageNamed:@"320tianjia-01"];
    [__worksImage setImageWithURL:[NSURL URLWithString:self.plazadataModel.worksImageURL]];
    

    
    // 标题
    _titleLabel.frame = CGRectMake(__worksImage.right+10, __worksImage.top+2 ,kLabelWidth, kLabelHeight);
    _titleLabel.textAlignment=NSTextAlignmentLeft;
    
    //_titleLabel.text = @"最好的风景";
    _titleLabel.text = self.plazadataModel.title;
    

    
    //名字
//    _personName.text=@"犀牛哥要peace";
    _personName.textColor = [UIColor lightGrayColor];
    _personName.font = [UIFont systemFontOfSize:13];
    
    _personName.frame = CGRectMake(_titleLabel.left,_titleLabel.bottom + 3,kLabelWidth - 100, kLabelHeight);
//    _personName.text = self.plazadataModel.personName;
    
    
    // 发布时间
//    _timeLabel.frame = CGRectMake(__worksImage.right+10, _personName.top, kLabelWidth, kLabelHeight);
//    _timeLabel.textAlignment = NSTextAlignmentRight;
//    _timeLabel.text=@"JUN 26 2015";
//    _timeLabel.textColor = [UIColor lightGrayColor];
//    
//    _timeLabel.font = [UIFont systemFontOfSize:14];
    // 处理日期字符串
//    NSRange range0 = NSMakeRange(0, 4);
//    NSString *year = [self.plazadataModel.releaseDate substringWithRange:range0];
//    
//    NSRange range1 = NSMakeRange(5, 2);
//    NSString *month=[self.plazadataModel.releaseDate substringWithRange:range1];
//    
//    NSRange range2 = NSMakeRange(8, 2);
//    NSString *day=[self.plazadataModel.releaseDate substringWithRange:range2];
//    
//    
//    // 月、日
//    if ([month isEqualToString:@"01"]) {
//        month = @"JAN";
//    } else if ([month isEqualToString:@"02"]) {
//        month = @"FEB";
//    }else if ([month isEqualToString:@"03"]) {
//        month = @"MAR";
//    }else if ([month isEqualToString:@"04"]) {
//        month = @"APR";
//    }else if ([month isEqualToString:@"05"]) {
//        month = @"MAY";
//    }else if ([month isEqualToString:@"06"]) {
//        month = @"JUN";
//    }else if ([month isEqualToString:@"07"]) {
//        month = @"JAN";
//    }else if ([month isEqualToString:@"08"]) {
//        month = @"AUG";
//    }else if ([month isEqualToString:@"09"]) {
//        month = @"SEP";
//    }else if ([month isEqualToString:@"10"]) {
//        month = @"OCT";
//    }else if ([month isEqualToString:@"11"]) {
//        month = @"NOV";
//    }else if ([month isEqualToString:@"12"]) {
//        month = @"DEC";
//    }
//    _timeLabel.text = [NSString stringWithFormat:@"%@ %@ %@",month,day,year];
    
    _playImage.frame = CGRectMake(self.width - 104, __worksImage.bottom - _personName.height + 5, _personName.height, _personName.height);
    _playCount.frame = CGRectMake(_playImage.right, _playImage.frame.origin.y, 30, _playImage.frame.size.width);
    _playCount.text = _plazadataModel.playTimes;
    
    _loveImage.frame = CGRectMake(_playCount.right, _playImage.top, _playImage.width, _playImage.height);
    _loveCount.frame = CGRectMake(_loveImage.right, _playImage.top, 30, _loveImage.height);
    _loveCount.text = _plazadataModel.heartCount;
    
    
    //分隔线
    UIImageView *downDivider = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.height, kDeviceWidth, 0.6)];
    downDivider.image = [UIImage imageNamed:@"gray_line"];
    
    [self.contentView addSubview:downDivider];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
